Skip to content

refactor: centralizing anchored graphic placement#3619

Open
VladaHarbour wants to merge 4 commits into
mainfrom
sd-3343_image-wrapping
Open

refactor: centralizing anchored graphic placement#3619
VladaHarbour wants to merge 4 commits into
mainfrom
sd-3343_image-wrapping

Conversation

@VladaHarbour
Copy link
Copy Markdown
Contributor

This PR does:

  • Centralizing anchored graphic placement (graphic-placement.ts) - small step towards bigger graphic refactor
  • Fixes wrapping issue

What is not included:

  • Vertical image misplacement (going to be in the next PR in order to separate things)

@VladaHarbour VladaHarbour self-assigned this Jun 3, 2026
@VladaHarbour VladaHarbour requested a review from a team as a code owner June 3, 2026 13:48
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Jun 3, 2026

SD-3343

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

I was unable to run the ecma-spec MCP lookups — every call returned "haven't granted it yet" (permission was declined in this session), so I'm reviewing against ECMA-376 §20.4.2 (DrawingML — WordprocessingDrawing) from spec knowledge rather than live tool confirmation. Flagging that up front per the faithful-reporting bar.

Status: PASS

The handler change (encode-image-node-helpers.js) only ever reads distT/distB/distL/distR off the wp:anchor node (lines 167–172) and merges them into the internal wrap model when the wrap child omitted them. All four of those attributes are legitimately defined on CT_Anchor, so no non-existent attribute is read, nothing required is dropped, and the "absent → use anchor value, skip if zero" defaulting is reasonable. No spec violation in the import path. See https://ooxml.dev/spec?q=anchor.

One nuance worth recording, though it isn't a hard violation in this diff:

  • mergeAnchorPaddingIntoWrapDistances is applied uniformly to Square, Tight, Through, and TopAndBottom (encode-image-node-helpers.js:290–292), merging all four sides. But per spec the wrap elements don't all carry all four distances:

    So the merge can stash, e.g., distLeft/distRight onto a TopAndBottom wrap model (or distTop/distBottom onto a Tight/Through model) — sides those wrap elements can't legally express. The source values are valid (they come from wp:anchor), and this stays in the internal PM model rather than emitting bad XML here, so it's not a spec violation in the importer. But if that model round-trips back onto the wrap child on export, it would produce attributes the wrap element doesn't allow. Notably the new TopAndBottom test deliberately passes distL:'0', distR:'0' (the !== 0 guard skips them) — which sidesteps the case but doesn't prevent it for a real non-zero anchor distL/distR.

Suggestion (non-blocking): gate the merge per wrap type — left/right only for Tight/Through, top/bottom only for TopAndBottom, all four for Square — to keep the model aligned with each element's spec-allowed attributes.

The rest of the diff (layout-engine graphic-placement, floating-objects, layout-adapter mergeWrapDistancesFromPadding) is layout/geometry, not OOXML serialization, so it's outside the spec-compliance scope.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b77d0df01

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/layout-engine/contracts/src/graphic-placement.ts
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread packages/layout-engine/contracts/src/graphic-placement.ts Outdated
Comment thread packages/layout-engine/contracts/src/graphic-placement.test.ts
@VladaHarbour VladaHarbour force-pushed the sd-3343_image-wrapping branch from 97dcc3e to 43bd145 Compare June 4, 2026 13:50
@VladaHarbour VladaHarbour force-pushed the sd-3343_image-wrapping branch from 43bd145 to 7937fa9 Compare June 4, 2026 14:16
@VladaHarbour
Copy link
Copy Markdown
Contributor Author

Hi @luccas-harbour! Visual testing regression must be addressed as well

Copy link
Copy Markdown
Contributor

@luccas-harbour luccas-harbour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing the comments!

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants